#!/bin/bash
# 传参检测
##################################################################
{% for host in groups['deploy'] %}
echo "{{host}} ceph_{{ host| regex_replace('\.', '_') }} " >> /etc/hosts
{% endfor %}

nethosts=`cat /etc/hosts |grep -v ^$|egrep -v "127.0.0.1|localhost"|awk  '{print $1}'`
#node节点上的密码，建议密码保持一致
rootpasswd="1"
###################################################################
# 在client机器做其他deploy的ssh免密操作
ssh(){
for i in  ${nethosts}
do
    echo "====================== ${i} ======================";
   echo ${i}
    if [[ ${USER} == 'root' ]];then
        [ ! -f /${USER}/.ssh/id_rsa ] &&\
        ssh-keygen -t rsa -P '' -f /${USER}/.ssh/id_rsa &>/dev/null
    else
        [ ! -f /home/${USER}/.ssh/id_rsa ] &&\
        ssh-keygen -t rsa -P '' -f /home/${USER}/.ssh/id_rsa &>/dev/null
    fi
    sshpass -p ${rootpasswd} ssh-copy-id -o StrictHostKeyChecking=no ${USER}@${i} &>/dev/null
done
}
ssh

a=`cat /etc/hosts |grep -v ^$|egrep -v "127.0.0.1|localhost"|awk  '{print $2}'`
for i in $a
    do
       scp root@${i}:/root/ceph-cluster/ceph.conf /etc/ceph/
       scp root@${i}:/root/ceph-cluster/ceph.client.admin.keyring /etc/ceph/
 done